﻿using System;
using System.Globalization;
using System.Windows.Data;
using JY.Common.Extensions;

namespace JY.Wpf.Core.Converters
{
    /// <summary>
    /// 枚举描述转换器
    /// </summary>
    public class EnumDescriptionConverter : IValueConverter
    {
        /// <summary>
        /// 将服务端枚举描述转换器
        /// </summary>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return "--";
            var valueType = value.GetType();
            return ((Enum)Enum.Parse(valueType, value.ToString())).GetEnumMember();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
